window.onload=function () {
    var app = new Vue({
        el: "#app",
        data: {
            rolearray:[],
            myobj:{
                label:"",
                rid:"",
                children:[]
            },
            data:[],
            mydata:[],
            pagination: {
                total: 0, //总记录数
                pageSize: 10, //每页的记录数
                pageNum: 1, //当前页码
            },
            statevalue:false,
            role:{ //修改状态对象
                rid:"",
                status:0,
                myvalue:""
            },
            addrole:false,//增加弹出框,,
            defaultProps: {
                children: 'children',
                label: 'label'
            },
            roles:{
                rid:"",
                status:0,
                rname:"",
                checkedarray:[]
            },
            roleupdatevalue:false,
            updatearray:[],
            updatedata:[],
            deleteSysRole:false

        },
        methods: {
            inisrole(){
                //初始化数据
                methodaxios.get(null,"/role/query?currentPage="+this.pagination.pageNum+"&pageSize="+this.pagination.pageSize,rep=>{
                    this.rolearray=rep.data.data.data;
                    this.pagination.total=rep.data.data.total;
                });
            },
            inistree(){
                methodaxios.get(null,"/role/queryrid",rep=>{
                    this.data=rep.data
                })
            },
            myswitch(row){//点击禁用按钮
                if(row.status==="1"){
                    this.role.status=0
                    this.role.myvalue="启用"
                }else{
                    this.role.status=1
                    this.role.myvalue="禁用"
                }
                this.role.rid=row.rid;
                this.statevalue=true
            },
            updatestate(){
                methodaxios.post("/role/updatestate",this.role,(rep)=>{
                    if(rep.data.code==="200"){
                        this.statevalue=false
                        this.inisrole();
                    }
                })
            },
            handleCheckChanges(data, checked, indeterminate){
                this.roles.checkedarray=checked.checkedKeys;
            },
            updatehandleCheckChanges(data, checked, indeterminate){
                this.updatearray=checked.checkedKeys;
            },
            //当前页发送改变
            findBlogPageList(page) {
                //页数改变
                this.pagination.pageNum = page;
                this.inisrole();
            },
            //每页大小发送改变
            sizeChange(size) {
                this.pagination.pageSize = size; //当前页显示多少
                this.pagination.pageNum = 1;
                this.inisrole();
            },
            confirmaddrole(){//点击增加角色按钮
                if(isBlank(this.roles.rname)){
                    layer.msg("请输入角色名称");
                    return false;
                }
                if(isBlank(this.roles.checkedarray)){
                    layer.msg("请分配权限");
                    return false;
                }
                methodaxios.post("/role/add",this.roles,rep=>{
                    if(rep.data.code==="200"){
                        this.addrole=false
                        this.inisrole();
                        this.inistree();
                        layer.msg("新增成功");
                        this.roles.rname=""
                        this.roles.checkedarray=[]
                    }
                })
            },
            adds(){
                this.addrole=true
                this.roles.rname=""
                methodaxios.get(null,"/role/queryallpermissions",rep=>{
                    this.mydata=rep.data
                })
            },
            roleupdate(rid,rname){//点击修改按钮
                this.updatedata=[]
                this.updatearray=[]
                this.roleupdatevalue=true
                this.roles.rname=rname;
                this.roles.rid=rid;
                var _this=this;
                methodaxios.get(null,"/role/queryallpermissions",rep=>{
                    _this.updatedata=rep.data
                    methodaxios.get({rid:rid},"/role/querypermissionsbyrid",rep=>{
                        _this.updatearray=rep.data
                    })
                })
            },
            confirmupdate(){//确定修改
                this.roles.checkedarray=this.updatearray;
                if(isBlank(this.roles.rname)){
                    layer.msg("请输入角色名称");
                    return false;
                }
                if(isBlank(this.roles.checkedarray)){
                    layer.msg("请分配权限");
                    return false;
                }
                methodaxios.post("/role/update",this.roles,rep=>{
                    if(rep.data.code==="200"){
                        this.roleupdatevalue=false
                        this.inisrole();
                        this.inistree();
                        layer.msg("修改成功");
                        this.roles.rname=""
                        this.roles.checkedarray=[]
                    }
                })
            },
            deleteSysRolemethod(rid,rname){//删除弹出框
                this.roles.rname=rname;
                this.roles.rid=rid;
                this.deleteSysRole=true;
            },
            confirmdelRole(){//确定删除
                methodaxios.get({rid: this.roles.rid},"/role/delete",rep=>{
                    this.deleteSysRole=false
                    this.inisrole();
                    this.inistree();
                    layer.msg("删除成功");
                    this.roles.rname=""
                })
            }
        },mounted() {
             this.inisrole();
             this.inistree();
         },
        filters:{
            mytime(value){
                var dateee = new Date( value).toJSON();
                return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
            }
        }

    })
}
